package com.qf.xiaomi.web.servlet;

import cn.dsna.util.images.ValidateCode;
import com.qf.xiaomi.utils.StringConstans;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/code")
public class CodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ValidateCode validateCode = new ValidateCode(100,30,4,8);
        validateCode.createCode();
        String code = validateCode.getCode();
        HttpSession session = req.getSession();
        session.setAttribute("code",code);
        System.out.println(code);
        try {
            validateCode.write(resp.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
